﻿using System;
using System.Collections.Generic;
using System.Linq;
using NMortgage.UI.Model;
using NMortgage.UI.Views;

namespace NMortgage.UI.ViewModels
{
    public sealed class SimulationViewModel : BaseViewModel
    {
        internal LoanProfileViewModel LoanProfileViewModel { get; set; }

        private List<PeriodicPaymentViewModel> _payments;

        public List<PeriodicPaymentViewModel> Payments

        {
            get { return _payments; }
            private set
            {
                _payments = value;
                NotifyOfPropertyChange(() => Payments);
            }
        }

        #region Properties

        public override string Title
        {
            get { return Properties.Resources.SimulationTitle; }
        }

        #endregion Properties


        public SimulationViewModel(LoanProfileViewModel loanProfileViewModel)
        {
            LoanProfileViewModel = loanProfileViewModel;
        }

        public void ShowAmortization()
        {
            var calculator = new MortgageCalculator(LoanProfileViewModel.LoanProfile);

            Payments = (from payment in calculator.Payments
                        select new PeriodicPaymentViewModel(payment, LoanProfileViewModel.LoanProfile)).ToList();

       }
    }
}
